package br.ufc.ck0017.ir.tree;

import java.util.ArrayList;
import java.util.List;


public class MOVE implements IRNode {
    public final IRNode destination;
    public final IRNode source;

    MOVE(IRNode destination, IRNode source) {
        this.destination = destination;
        this.source = source;
    }

    @Override
    public List<IRNode> getChildren() {
        List<IRNode> children = new ArrayList<>(2);

        if (destination instanceof MEM) {
            children.add(((MEM) destination).getIRNode());
            children.add(source);
        } else {
            children.add(source);
        }

        return children;
    }

    @Override
    public IRNode build(List<IRNode> children) {
        if (destination instanceof MEM) {
            return new MOVE(new MEM(children.get(0)), children.get(1));
        }

        return new MOVE(destination, children.get(0));
    }
}
